package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.combat.attr.CombatAttribute;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.employee.template.EmployeeComboTemplate;
import com.xcity.game.employee.template.EmployeeTemplate;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class EmployeeComboInfoResponse extends Response {
	
	public int id;
	public List<ComboInfo> list = Collections.emptyList();
	
	public static class ComboInfo {
		public String name;
		public List<ViceCard> viceCards;
		public List<Short> attrsIndex;
		public List<Object> attrs;
		public byte state; // 该羁绊状态（0-未激活，1-已激活）
	}
	
	// 可产生羁绊的员工模板信息
	public static class ViceCard {
		public int id; // 员工模板id
		public byte state; // 0-没有该员工，1-拥有该员工
	}
	
	public EmployeeComboInfoResponse(int serial, Player player, EmployeeTemplate employee) {
		super(serial);
		this.id = employee.getId();
		List<EmployeeComboTemplate> comboTemplates = employee.getCombos();
		if (comboTemplates != null) {
			this.list = new ArrayList<ComboInfo>(comboTemplates.size());
			for (int i = 0; i < comboTemplates.size(); i++) {
				EmployeeComboTemplate template = comboTemplates.get(i);
				ComboInfo info = new ComboInfo();
				info.state = 1;
				info.name = template.getName();
				int[] viceIds = template.getViceIds();
				info.viceCards = new ArrayList<>(viceIds.length);
				for (int viceId : viceIds) {
					ViceCard vc = new ViceCard();
					vc.id = viceId;
					vc.state = (byte) (player.getEmployees().size(viceId, null) > 0 ? 1 : 0);
					if (vc.state == 0) {
						info.state = 0;
					}
					info.viceCards.add(vc);
				}
				CombatAttribute[] attrs = template.getAttributes();
				int len = attrs.length;
				info.attrsIndex = new ArrayList<>(len);
				info.attrs = new ArrayList<>(len);
				for (CombatAttribute attr : attrs) {
					CombatAttributeType type = attr.getType();
					if (type != CombatAttributeType.MAGIC_POWER
							&& type != CombatAttributeType.MAGIC_DEFENSE) {
						// 物攻、法攻合并显示为攻击，物防、法防合并显示为防御
						info.attrsIndex.add((short) type.ordinal());
						info.attrs.add(attr.format(attr.getValue()));
					}
				}
				this.list.add(info);
			}
		}
	}
	
}
